package com.jar.exercise.多线程.atomic.AtomicInteger;

/**
 * 先行发生原则 3 volatile变量规则：对一个变量的写操作先行发生于后面对这个变量的读操作
 */
public class Demo4 {
	private static boolean ready;
	private static int number;

	private static class ReaderThread extends Thread {
		@Override
		public void run() {
			while (!ready) {
				Thread.yield();
			}
			System.out.println(number);

		}
	}

	public static void main(String[] args) throws InterruptedException {
		new ReaderThread().start();
		number = 42;
		ready = true;
	}
}